
inputfiles="D:\\PyProgram\\MeshCombined.tcl"

# ====================== Output tcl files ====================
outputfiles="D:\\installfiles\\Opnesees\\OpenSeesParallel2.5.0-x64\\OpenSeesParallel2.5.0-x64\\BeamCouple.txt"

# ====================== Geotransf No. (Geotransf will NOT be automatically created) ============
rgn=2

# ====================== Rigid Material No. (Material will NOT be automatically created)================================
rmn=2

# ====================== Rigid forceBeamColumn Element Starting No. =========
ren=10001

# ====================== Beam end node No. (can be created)
ben=9232
bex=3
bey=0
bez=0

# ====================== Rigid Section No. (a new one will be created)
rsc=1
length=0.5

# ====================== Input completes =====================
content=open(inputfiles)
NodeList=[]
SelectedList=[]
for line in content:
    splited=line.split()
    if len(splited)>0:
        if splited[0]=='node':
            NodeList.append(int(splited[1]))
            #Selection Condition, splited[2] is x coord, splited[3] is y coord, splited[4] is z coord
            if abs(float(splited[2])-3)<1e-5:
                SelectedList.append(int(splited[1]))
            
content.close()
print(SelectedList)
print('Total:',len(SelectedList))

newf=open(outputfiles,'w')
if ben in SelectedList:
    pass
else:
    newf.write('node %d %f %f %f'%(ben,bex,bey,bez))
    newf.write('\n')

newf.write('\n')  
newf.write('section Fiber %d {'%(rsc))
newf.write('\n')
newf.write('patch rect %d 3 3 %f %f %f %f'%(rmn,-length,-length,length,length))
newf.write('\n')
newf.write('}')

newf.write('\n')
for i in range(0,len(SelectedList)):
    newf.write('element forceBeamColumn %d %d %d 5 %d %d'%(ren,ben,SelectedList[i],rsc,rmn))
    newf.write('\n')
    ren=ren+1
newf.close